package com.yc.yyds.servlet;

import com.google.gson.Gson;
import com.yc.yyds.Bean.Result;
import com.yc.yyds.biz.BizException;
import com.yc.yyds.biz.QueryLinksBiz;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@WebServlet(name = "UserQueryLinksServlet", value = "/UserQueryLinksServlet.s")
public class UserQueryLinksServlet extends HttpServlet {

    QueryLinksBiz biz = new QueryLinksBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        //声明实体类
        Result result = null;
        PrintWriter out = response.getWriter();
        try {
            final List<Map<String, Object>> data = biz.queryLink();
            result = new Result(1,null,data);
            String json = new Gson().toJson(result);
            out.append(json);
        } catch (BizException e) {
            e.printStackTrace();
            result = new Result(0,e.getMessage(),null);
            String json = new Gson().toJson(result);
            out.append(json);
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
